﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Sample.Interfaces;
using Sample.Modules.MainContent.ViewModels;
using UnityExtensions;

namespace Sample.Modules.MainContent.Views
{
    public partial class MainContentView
    {
        private MainContentViewModel _viewModel;

        public MainContentView(MainContentViewModel viewModel)
        {
            InitializeComponent();
            DataContext = viewModel;
            _viewModel = viewModel;
        }

        private void MainListView_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var originalSource = (DependencyObject)e.OriginalSource;
            var listViewItem = originalSource.FindAncestor<ListViewItem>();
            if (listViewItem != null)
            {
                var item = (IBook)listViewItem.DataContext;
                _viewModel.ItemDoubleClicked(item);
            }
        }
    }
}
